package com.gali.juc;

import java.util.concurrent.*;
import java.util.concurrent.CompletableFuture;

/**
 * @Auther: gali
 * @Date: 2022-08-18 19:43
 * @Description:
 */
public class CompletableFutureBuilder {
    public static void main(String[] args) throws ExecutionException, InterruptedException {
            ExecutorService executorService = Executors.newFixedThreadPool(3);
    //        CompletableFuture<Void> completableFuture=CompletableFuture.runAsync(()->{
    //            System.out.println(Thread.currentThread().getName());
    //            try {
    //                TimeUnit.SECONDS.sleep(1);
    //            } catch (InterruptedException e) {
    //                e.printStackTrace();
    //            }
    //        },executorService);
    //        System.out.println(completableFuture.get());
    //        executorService.shutdown();
            CompletableFuture<String> completableFuture=CompletableFuture.supplyAsync(()->{
                System.out.println(Thread.currentThread().getName());
                try {
                    TimeUnit.SECONDS.sleep(1);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                return "hello,completableFuture";
            },executorService);
        System.out.println(completableFuture.get());
        executorService.shutdown();
    }
}
